<template>
  <div class="table_data">
      <WarnHeader />
      <el-table :data="syswarnlist" :cell-style="{'text-align':'center'}" :header-cell-style="{background: '#f8f8f9',textAlign: 'center'}">
        <el-table-column width="80" show-overflow-tooltip prop="id" label="序号"></el-table-column>
        <el-table-column width="150" show-overflow-tooltip  label="预警类型">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.warnType == 1" type="warning">拱顶下沉预警</el-tag>
            <el-tag v-if="scope.row.warnType == 2" type="info">拱脚下沉预警</el-tag>
            <el-tag v-if="scope.row.warnType == 3" type="success">周边收敛预警</el-tag>
            <el-tag v-if="scope.row.warnType == 4" type="success">超前地质预报预警</el-tag>
            <el-tag v-if="scope.row.warnType == 5" type="success">初支施工质量预警</el-tag>
            <el-tag v-if="scope.row.warnType == 6" type="success">二衬施工质量预警</el-tag>
          </template>
        </el-table-column>
        <el-table-column width="100" show-overflow-tooltip prop="warnValue" label="预警值"></el-table-column>
        <el-table-column width="200" show-overflow-tooltip prop="createTime" label="创建时间"></el-table-column>
        <el-table-column show-overflow-tooltip label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              icon="el-icon-edit"
              @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button>
            <el-button
              size="mini"
              type="danger"
              icon="el-icon-delete"
              @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
            @current-change="handleCurrentChange"
            layout="total, sizes, prev, pager, next, jumper"
            :total="currentPage.total"
        ></el-pagination>
      </div>
    <WarnEditor :flag="flag" />
  </div>
</template>
<script>
import api from '../../../api'
import qs from 'qs'
import WarnEditor from './WarnEditor.vue'
import WarnHeader from './WarnHeader.vue'
export default {
  data() {
    return {
      tunnelInfoChild: [],
      wId: '', // 洞幅id
      syswarnlist: [],
      flag: false,
      value: '--全部--',
      currentPage: {
        pageNo: 1,
        total: 0
      }
    }
  },
  components: {
    WarnEditor,
    WarnHeader
  },
  mounted() {
    this.http(1)
    this.$bus.$on('onRefreshSyswarn', (flag) => {
      this.http(1)
    })
  },
  methods: {
    http(page) {
      api
        .sysWarnfindByAll({ page })
        .then((res) => {
          if (res.data.code == 2001) {
            this.syswarnlist = res.data.data.records
          }
        })
        .catch((error) => {
          console.log(error)
        })
    },
    handleEdit(index, row) {
      this.$bus.$emit('onShowSyswarnEditor', { rowdata: row })
    },
    handleDelete(index, row) {
      let data = {
        id: row.id
      }
      this.$confirm('此操作将永久删除预警信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        customClass: 'del-model',
        type: 'warning'
      })
        .then(() => {
          api
            .sysWarndeleteById(qs.stringify(data))
            .then((res) => {
              if (res.data.code == 2001) {
                this.$message({
                  type: 'success',
                  message: '删除成功!'
                })
                // 视图重绘
                this.http(1)
              } else {
                this.$message({
                  type: 'fail',
                  message: '删除失败!'
                })
              }
            })
            .catch((err) => {
              console.log(err)
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    handleCurrentChange(val) {
      this.http(val, this.tid)
    }
  }
}
</script>

<style scoped>
.el-table{
  margin-top: 20px;
}
</style>